package com.example.projectjava.dao;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

//针对appUser表做SQL操作的类
@Repository   //此注解的作用：与控制器中的@Controller注解的功能相同，意为将该类纳入Spring容器管理
public class LogisticDao {

    @Autowired
    JdbcTemplate jdbcTemplate;

    public  int insertLogistic(String dvy_id,String dvy_name,String company_home_url,String query_url){
        String sql = "insert into tz_delivery(dvy_id,dvy_name,company_home_url,query_url) values(?,?,?,?)";
        return    jdbcTemplate.update(sql,dvy_id,dvy_name,company_home_url,query_url);
    }

    public  int deleteLogistic(String dvy_name){
        String sql  = "DELETE from tz_delivery where dvy_name=?";
        return  jdbcTemplate.update(sql,dvy_name);
    }

    public List<Map<String,Object>> queryAllLogistic(){
        String sql = "select * from tz_delivery";
        return  jdbcTemplate.queryForList(sql);
    }

    public int updateLogistic(String dvy_id, String dvy_name, String company_home_url, String query_url){
        String sql = "update tz_delivery set dvy_id=?,company_home_url=?,query_url=? where dvy_name=?";
        return  jdbcTemplate.update(sql,dvy_id,company_home_url,query_url,dvy_name);
    }
}
